package com.itheima.health.config;

import com.itheima.health.security.intercept.SecurityInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置运行所有的请求跨域
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    @Autowired
    private SecurityInterceptor securityInterceptor;


    /**
     * 注册自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(securityInterceptor).addPathPatterns("/**");
    }

    /**
     * 配置 跨域问题
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")// 针对所有的请求
            .allowedOrigins("*")    // 允许来自所有的域
            .allowedMethods("*")    // 允许所有的HTTP Method
            .allowCredentials(true);// 允许携带cookie
    }


}